package com.tentact.servlets;

import com.tentact.service.Chf_MeetingService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Chf_addMeetingServlet", value = "/Chf_addMeetingServlet")
public class Chf_addMeetingServlet extends HttpServlet {
    Chf_MeetingService c_ms = new Chf_MeetingService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String meeting_name = request.getParameter("meeting_name");
        int h_number = Integer.parseInt(request.getParameter("h_number"));
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        int roomid = Integer.parseInt(request.getParameter("roomid"));
        String description = request.getParameter("description");
        HttpSession session = request.getSession();
        int reservationistid = (int)session.getAttribute("employeeid");
        String[] add_Employees = request.getParameterValues("add_Employees");
        c_ms.addMeeting(meeting_name, h_number, startTime, endTime, roomid, description, reservationistid);
        int s1 = c_ms.meetingID(meeting_name);
        System.out.println(meeting_name);
        System.out.println(h_number);
        System.out.println(startTime);
        System.out.println(endTime);
        System.out.println(roomid);
        System.out.println(description);
        System.out.println(reservationistid);

        for (String e : add_Employees) {
            int s2 = Integer.parseInt(e);
            c_ms.addMeetingParticipant(s1, s2);
            System.out.println("s2:" + s2);
        }


        request.getRequestDispatcher("test.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
